package com.zb.order.controller;

import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjWorkModuleFieldService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkModuleFieldVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author WEN
 * @Date 2023/10/7 0007
 **/
@Api(tags = "工单模块工单自定义字段类接口")
@RestController
@RequestMapping("/work/module/field")
public class ZjWorkModuleFieldController {
    @Resource
    private ZjWorkModuleFieldService workModuleFieldService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单模块-工单字段 - 新增或修改工单自定义字段")
    @ApiOperation("新增或修改工单自定义字段")
    @PostMapping("/save/{moduleId}")
    public Result save(HttpServletRequest request, @PathVariable @ApiParam(value = "工单模块ID", required = true) Long moduleId,
                       @RequestBody @Valid WorkModuleFieldVo moduleFieldVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workModuleFieldService.save(custAccId, moduleId, moduleFieldVo);
        return Result.success(null == moduleFieldVo.getId()? "新增工单字段成功" : "修改工单字段成功");
    }

    @ApiOperation("获取工单字段列表")
    @PostMapping("/getList/{moduleId}")
    public Result getList(@PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId, @RequestBody PageUtil pageUtil) {
        return Result.success("获取工单字段列表成功").data(workModuleFieldService.getList(moduleId, pageUtil));
    }

    @ApiOperation("根据ID获取工单字段详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "工单模块自定义工单字段ID") Long id) {
        return Result.success("获取工单字段详情成功").data("row", workModuleFieldService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单字段 - 批量更新字段必填项")
    @ApiOperation("批量更新字段必填项")
    @PutMapping("/requiredField")
    public Result requiredField(@RequestParam @ApiParam(value = "是否必填：false-不必填，true-必填", required = true, example = "true") boolean required,
                                @RequestBody @ApiParam(value = "工单模块自定义工单字段ID", required = true)List<Long> idList) {
        workModuleFieldService.updateRequiredBatchById(idList, required);
        return Result.success("必填项更改成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单字段 - 批量更新移动显示项")
    @ApiOperation("批量更新移动端显示项")
    @PutMapping("/mobileShow")
    public Result mobileShow(@RequestParam @ApiParam(value = "是否移动端显示：false-不展示，true-展示", required = true, example = "false") boolean mobileShow,
                                @RequestBody @ApiParam(value = "工单模块自定义工单字段ID", required = true)List<Long> idList) {
        workModuleFieldService.updateMobileShowBatchById(idList, mobileShow);
        return Result.success("移动端显示项更改成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单字段 - 批量更新移动显示项")
    @ApiOperation("批量更新是否作为列表查询条件项")
    @PutMapping("/listSelect")
    public Result listSelect(@RequestParam @ApiParam(value = "是否作为列表查询条件：false-不作为查询条件，true-作为查询条件", required = true, example = "false") boolean listSelect,
                             @RequestBody @ApiParam(value = "工单模块自定义工单字段ID", required = true)List<Long> idList) {
        workModuleFieldService.updateListSelectBatchById(idList, listSelect);
        return Result.success("列表查询条件项更改成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单字段 - 批量更新移动显示项")
    @ApiOperation("批量更新是否在列表展示项")
    @PutMapping("/listShow")
    public Result listShow(@RequestParam @ApiParam(value = "是否在列表展示：false-不在列表展示，true-在列表展示", required = true, example = "false") boolean listShow,
                             @RequestBody @ApiParam(value = "工单模块自定义工单字段ID", required = true)List<Long> idList) {
        workModuleFieldService.updateListShowBatchById(idList, listShow);
        return Result.success("列表展示项更改成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单字段 - 批量更新移动显示项")
    @ApiOperation("批量删除工单模块自定义工单字段")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "工单模块自定义工单字段ID", required = true)List<Long> idList) {
        workModuleFieldService.deleteBatchById(idList);
        return Result.success("删除成功");
    }

    @ApiOperation("根据模块ID获取工单自定义字段")
    @GetMapping("/getModuleField/{moduleId}")
    public Result getModuleField(@PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId) {
        return Result.success("获取模块工单自定义字段成功").data("row", workModuleFieldService.getModuleField(false, moduleId));
    }




}
